package jfprincesstests.fakes;

import jfuzzyprincepless.zarchive.algorithm.structure.forcnstr.IForConstruction;
import jfuzzyprincepless.zarchive.algorithm.structure.forcnstr.fuzzyfor.IFuzzyForConstruction;
import jfuzzyprincepless.zarchive.negotiation.services.IExecuteForService;
import jfuzzyprincepless.negotiation.IExecutionContext;
import jfuzzyprincepless.negotiation.INegotiationContext;

public class FakeForCmd<E> extends FakeCmd {
	// DECIDE: separate: command, negotiation agent, negotiation result ( ==? negotiation context)
	/* ### ### ### ### ### ### ### ### ### ###
	 * negotiation agents store data not in it's fields, but in negotiation context
	 * negotiation agents are CONST
	 */

	public FakeForCmd(StringBuilder sb, String command) {
		super(sb, command);
	}

	@SuppressWarnings("unchecked")
	@Override
	public void execute(IExecutionContext econtext) {
		INegotiationContext ncontext =
			(INegotiationContext) econtext;
		IExecuteForService<E> forServ =
			ncontext.getService(IExecuteForService.class);
		sb.append(command).append(forServ.getCurrentElem());

		IForConstruction<E> forConstr =
			forServ.getForConstruction();
		if (forConstr instanceof IFuzzyForConstruction<?>) {
			IFuzzyForConstruction<E> fforConstr =
				(IFuzzyForConstruction<E>)forConstr;
			double membershipDegree = fforConstr.getFuzzyForSet()
				.getMembershipDegree(forServ.getCurrentElem());
			sb.append("mem").append(membershipDegree);
		}
	}
}
